route.tsx 851 B

1234567891011121314151617181920212223242526272829
  1. import { getPageImage, source } from '@/lib/source';
  2. import { notFound } from 'next/navigation';
  3. import { ImageResponse } from 'next/og';
  4. import { generate as DefaultImage } from 'fumadocs-ui/og';
  5. import { appName } from '@/lib/shared';
  6. export const dynamic = 'force-static';
  7. export const revalidate = false;
  8. export async function GET(_req: Request, { params }: RouteContext<'/og/docs/[...slug]'>) {
  9. const { slug } = await params;
  10. const page = source.getPage(slug.slice(0, -1));
  11. if (!page) notFound();
  12. return new ImageResponse(
  13. <DefaultImage title={page.data.title} description={page.data.description} site={appName} />,
  14. {
  15. width: 1200,
  16. height: 630,
  17. },
  18. );
  19. }
  20. export function generateStaticParams() {
  21. return source.getPages().map((page) => ({
  22. lang: page.locale,
  23. slug: getPageImage(page).segments,
  24. }));
  25. }